% AIRCRAFT CONFIGURATION SCRIPT
%   Tempest UAV 
%   Revision: 1.0   Date: 02/02/10
%   Jason Roadman
%   Derivatives about a nominal flight condition of:
%     - 20 m/s cruise
%     - 5000' density altitude
%     - 13 lb take-off weight
%     --> C_L = 0.434
%     - all control surfaces zeroed
%   Origin located at wing LE
%   All values calculated using AVL unless otherwise noted

% Clear workspace
clear all;

% Name of the MAT-file that will be generated
cfgmatfile = 'tempestcfg';

%%% AERODYNAMICS %%%
% Aerodynamic force application point (usually the aerodynamic center)[x y z]
rAC = [-0.1505 0 0]; % m

%%% Aerodynamic parameter bounds %%%
% Airspeed bounds
VaBnd = [15 50]; % m/s
% Sideslip angle bounds
BetaBnd = [-0.5 0.5]; % rad
% Angle of attack bounds
AlphaBnd = [-0.1 0.3]; % rad

%%% Aerodynamic reference parameters %%%
% Mean aerodynamic chord
MAC = 0.208; % m
% Wind span
b = 3.2229; % m
% Wing area
S = 0.6316; % m^2

% ALL aerodynamics derivatives are per radian:
%%% Lift coefficient %%%
% Zero-alpha lift
CL0 = 0.2259;
% alpha derivative
CLa = 6.1953;
% Lift control (flap) derivative
CLdf = 1.609;
% Pitch control (elevator) derivative
CLde = 0.3882;
% alpha-dot derivative
CLalphadot = 1.9724; %taken from Aerosonde config, AVL doesn't calculate
% Pitch rate derivative
CLq = 10.128;
% Mach number derivative
CLM = 0;

%%% Drag coefficient %%%
% Lift at minimum drag
CLmind = 0.23; %Aerosonde used 0.23;
% Minimum drag
CDmin = 0.0434; %Aerosonde used 0.0434;
% Lift control (flap) derivative
CDdf = 0.1467; %from Aerosonde, AVL only calculates change in induced as 0.0243
% Pitch control (elevator) derivative
CDde = 0.0135; %from Aerosonde, AVL only calculates change in induced as 0.00361
% Roll control (aileron) derivative
CDda = 0.0302; %from Aerosonde, AVL only calculates change in induced as 0.0000
% Yaw control (rudder) derivative
CDdr = 0.0303; %from Aerosonde, AVL only calculates change in induced as 0.0000
% Mach number derivative
CDM = 0;
% Oswald's coefficient
osw = 0.75; %from Aerosonde, AVL is overexaggerating what is possible without fuselage

%%% Side force coefficient %%%
% Sideslip derivative
CYbeta = -0.3672;
% Roll control derivative
CYda = -0.0432;
% Yaw control derivative
CYdr = 0.1750;
% Roll rate derivative
CYp = -0.0629;
% Yaw rate derivative
CYr = 0.2138;

%%% Pitch moment coefficient %%%
% Zero-alpha pitch
Cm0 = 0.0320;
% alpha derivative
Cma = -1.6433;
% Lift control derivative
Cmdf = 0.2266;
% Pitch control derivative
Cmde = -1.6440;
% alpha_dot derivative
Cmalphadot = -10.3796; %taken from Aerosonde config, AVL doesn't calculate
% Pitch rate derivative
Cmq = -24.3928;
% Mach number derivative
CmM = 0;

%%% Roll moment coefficient %%%
% Sideslip derivative
Clbeta = -0.0812;
% Roll control derivative
Clda = -0.3603;
% Yaw control derivative
Cldr = 0.0090;
% Roll rate derivative
Clp = -0.6864;
% Yaw rate derivative
Clr = 0.1220;

%%% Yaw moment coefficient %%%
% Sideslip derivative
Cnbeta = 0.0806;
% Roll control derivative
Cnda = -0.0048;
% Yaw control derivative
Cndr = -0.0490;
% Roll rate derivative
Cnp = -0.0408;
% Yaw rate derivative
Cnr = -0.0523;


%%% PROPELLER %%%
%Propulsion force application point (usually propeller hub) [x y z]
rHub = [0.4128 0 0.0381]; % m
%------------------------------------------------------------------------------
% Advance ratio vector
J = [0.000 0.050 0.100 0.150 0.200 0.250 0.300 0.350 0.400 0.450  0.500  0.550 0.600 0.610 0.620 0.630 0.640 0.650 0.660 0.670 0.680 0.690 0.700 0.710 0.720 0.730 0.740 0.750 0.760 0.770];
% Coefficient of thrust look-up table CT = CT(J)
CT = [0.065849 0.068441 0.070174 0.067831 0.065289 0.063120 0.059986 0.055819 0.050562 0.044532	 0.038057	 0.031372 0.024486 0.023087 0.021681 0.020269 0.018848 0.017419 0.015988 0.014546 0.013100 0.011646 0.010186 0.008719 0.007248 0.005764 0.004277 0.002778 0.001274 -0.000236];
% Coefficient of power look-up table CP = CP(J)
CP = [0.029631 0.029450 0.029116 0.028922 0.029640 0.029815 0.029987 0.029694 0.028847 0.027337 0.025222 0.022568 0.019338 0.018620 0.017878 0.017112 0.016320 0.015502 0.014662 0.013793 0.012900 0.011980 0.011035 0.010062 0.009064 0.008035 0.006981 0.005895 0.004782 0.003643];
% Propeller radius
Rprop = 0.2350; % m
% Propeller moment of inertia
Jprop = 0.002; % kg*m^2  %ASSUMED FROM AEROSONDE


%%% ENGINE %%%
% Engine rpm vector
%RPM = [1500 2100 2800 3500 4500 5100 5500 6000 7000]; % rot per min
%RPM = [4295.3 4418.4 4541.6 4664.7 4787.9 4911 5034.2 5157.3 5280.4];
RPM = [ 0 796.88 1593.8 2390.6 3187.5 3984.4 4781.2 5578.1 6375 ];
% Manifold pressure vector
%MAP = [0 0 0 0 0 0 0 0 0]; % kPa
% Throttle vector
MAP = [0 12.5 25 37.5 50 62.5 75 87.5 100]./100; %

% Sea-level fuel flow look-up table fflow = fflow(RPM, MAP)
% RPM -> rows, MAP -> columns
FuelFlow = [
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0
]; % g/hr
% Sea-level power look-up table P = P(RPM, Thr)
% RPM -> rows, Thr -> columns
%Power = [
%    0.6808  0.2541  1.4578  0.9916   0.384  0.4263  0.0853   0.3602   0.8781
%    2.5408  1.1545  4.3972  3.2305  1.5171  1.6379  0.4460     1.42   2.9139
%    9.4547  5.2343  13.219  10.494  5.9822  6.2804  2.3283   5.5874   9.6429
%    34.805  23.535  39.337  33.771  23.412  23.901  12.097   21.832   31.628
%    123.29  102.06  113.67  105.53  89.019  88.439  61.403   83.048   100.82
%    385.84  384.01   303.4  302.74  305.75  297.09  279.22   287.22   295.23
%    897.34  979.36   677.9  708.75   795.9  768.93  869.62    762.5   703.67
%    1390.9  1486.5  1146.1  1203.6  1338.8  1310.1  1460.8   1313.6   1205.8
%      1631  1677.7  1485.7  1531.3  1617.9  1603.7  1679.2   1608.2   1535.7
%]; % W

Power = [
	0.3976 0.3976 0.3976 0.3976 0.3976 0.3976 0.3976 0.3976 0.3976
	2.2189 2.2189 2.2189 2.2189 2.2189 2.2189 2.2189 2.2189 2.2189
	10.086 10.086 10.086 10.086 10.086 10.086 10.086 10.086 10.086
	37.474 37.474 37.474 37.474 37.474 37.474 37.474 37.474 37.474
	114.33 114.33 114.33 114.33 114.33 114.33 114.33 114.33 114.33
	288.19 288.19 288.19 288.19 288.19 288.19 288.19 288.19 288.19
	605.24 605.24 605.24 605.24 605.24 605.24 605.24 605.24 605.24
	1071.4 1071.4 1071.4 1071.4 1071.4 1071.4 1071.4 1071.4 1071.4
	1623.9 1623.9 1623.9 1623.9 1623.9 1623.9 1623.9 1623.9 1623.9
]; % W

% Sea-level pressure and temperature at which the data above is given
pSL = 101325; % Pa                 FIXME -- not sure about this
TSL = 291.15; % deg K              FIXME -- not sure about this
% Engine shaft moment of inertia
Jeng = 0.0001; % kg*m^2            FIXME -- not sure about this
%------------------------------------------------------------------------------

%%% INERTIA %%%
% Empty aircraft mass (zero-fuel)
%mempty = 5.91; % kg
mempty = 5.905; % kg
% Gross aircraft mass (full fuel tank)
mgross = 5.915; % kg
% Empty CG location [x y z]
%CGempty = [-0.0953 0 0.0381]; % m
CGempty = [-0.0952 0 0.0380]; % m  TRICK FOR NO CG CHANGE
% Gross CG location [x y z]
CGgross = [-0.0954 0 0.0382]; % m
% Empty moments of inertia [Jx Jy Jz Jxz]
%Jempty = [1.159 0.851 1.950 0.099]; % kg*m^2
Jempty = [1.158 0.851 1.949 0.98]; % kg*m^2  % TRICK FOR NO J CHANGE
% Gross moments of inertia [Jx Jy Jz Jxz]
Jgross = [1.160 0.851 1.951 1.00]; % kg*m^2


%%% OTHER SIMULATION PARAMETERS %%%
% WMM-2000 date [day month year]
dmy = [02 02 2010];

% Save workspace variables to MAT file
save(cfgmatfile);

% Output a message to the screen
fprintf(strcat('\n Aircraft configuration saved as:\t', strcat(cfgmatfile),'.mat'));
fprintf('\n');
